﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
using WebChatApi.Common.Interface;

namespace WebChatApi.Common
{
    /// <summary>
    /// Class for runtime template
    /// </summary>
    public class RuntimeTemplate : Template
    {
        #region Properties

        /// <summary>
        /// Gets or sets the user info.
        /// </summary>
        /// <value>
        /// The user info.
        /// </value>
        public IUserInfo UserInfo
        {
            get;
            set;
        }

        /// <summary>
        /// Gets or sets the stamp info.
        /// </summary>
        /// <value>
        /// The stamp info.
        /// </value>
        public string StampInfo
        {
            get;
            set;
        }

        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="RuntimeTemplate" /> class.
        /// </summary>
        /// <param name="userInfo">The user info.</param>
        /// <param name="stampInfo">The stamp info.</param>
        public RuntimeTemplate(IUserInfo userInfo, string stampInfo)
            : base()
        {
            this.UserInfo = userInfo;
            this.StampInfo = stampInfo;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="RuntimeTemplate"/> class.
        /// </summary>
        /// <param name="userInfo">The user info.</param>
        public RuntimeTemplate(IUserInfo userInfo)
            : this(userInfo, DateTime.UtcNow.ToString("yyyyMMddHHmm"))
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="RuntimeTemplate"/> class.
        /// </summary>
        public RuntimeTemplate()
            : this(null)
        {
        }

        #region Public methods

        /// <summary>
        /// Generates the place holders.
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, string> GeneratePlaceHolders()
        {
            Dictionary<string, string> result = new Dictionary<string, string>();
            foreach (PlaceHolderKeywords value in Enum.GetValues(typeof(PlaceHolderKeywords)))
            {
                result.Add(value.ToString(), GetReplaceValue(value, this, this.UserInfo, this.StampInfo));
            }

            return result;
        }

        #endregion


    }
}
